package com.glela.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.request.RequestUserModel;
import com.glela.platform.model.response.ResponseBaseModel;
import com.glela.platform.model.response.ResponseResultModel;
import com.glela.platform.model.response.ResponsrUserRemark;
import com.glela.platform.service.UserRemarkService;
import com.glela.platform.util.ParameterUtils;

@Controller
@RequestMapping(value = "/userRemark")
public class UserRemarkController {
	private static Logger logger = LoggerFactory.getLogger(UserController.class);
	@Autowired
	private UserRemarkService userRemarkService;

	/**
	 * x查询备注
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/selectUserRemark", method = RequestMethod.POST, consumes = "application/json")
	public ResponseEntity<?> selectUserRemark(@RequestBody RequestUserModel model) {
		try {
			if (ParameterUtils.validParams(model.getUserId(), model.getRemarkManId())) {
				return new ResponseEntity<ResponseBaseModel>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
			}
			ResponsrUserRemark responsrUserRemark = userRemarkService.selectUserRemark(model.getUserId(),
					model.getRemarkManId());
			return new ResponseEntity<>(new ResponseResultModel<ResponsrUserRemark>(responsrUserRemark), HttpStatus.OK);
		} catch (Exception e) {
			logger.error("查询备注异常:", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}

	/**
	 * 添加备注
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/insertRemark", method = RequestMethod.POST, consumes = "application/json")
	public ResponseEntity<?> insertRemark(@RequestBody RequestUserModel model) {
		try {
			if (ParameterUtils.validParams(model.getUserId(), model.getRemarkManId(), model.getRemark())) {
				return new ResponseEntity<ResponseBaseModel>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
			}
			int i = userRemarkService.insertRemark(model.getUserId(), model.getRemarkManId(), model.getRemark());
			if (i == 1) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C10000), HttpStatus.OK);
			} else {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
			}
		} catch (Exception e) {
			logger.error("查询备注异常:", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}
}
